package org.op.service;

import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;

import org.op.service.config.ConfigKeys;
import org.op.service.config.ConfigurationService;
import org.op.service.log.LoggerService;
import org.op.service.ui.UiService;

public class ServiceManager {
	
	private ConfigurationService configService;
	private LoggerService loggingService;
	private UiService uiService;
	
	public void startupServices() {
		// probably unnecessary, use the init-method parm in beans.xml
		String defaultLogPath = configService.getApplicationHome() + ConfigurationService.FILE_SEP + "noteking.log";
		String appLogPath = configService.getProperty(ConfigKeys.APPLICATION_LOG_PATH);
		if (appLogPath==null || appLogPath.trim().equals("")) {
			appLogPath = defaultLogPath;
		}
		try {
			loggingService.init(appLogPath);
		} catch (Exception e) {
			// cant init the logging path??  oh well.. no logs for you
			e.printStackTrace();
		}
		
		Date now = Calendar.getInstance().getTime();
		String nowString = DateFormat.getDateInstance(DateFormat.MEDIUM).format(now);
		
		loggingService.log("Services startup at " + nowString);
	}

	public ConfigurationService getConfigService() {
		return configService;
	}

	public void setConfigService(ConfigurationService configService) {
		this.configService = configService;
	}

	public LoggerService getLoggingService() {
		return loggingService;
	}

	public void setLoggingService(LoggerService loggingService) {
		this.loggingService = loggingService;
	}

	public UiService getUiService() {
		return uiService;
	}

	public void setUiService(UiService uiService) {
		this.uiService = uiService;
	}
	
	
}
